package com.david.mydemo.ctl_storage.config;


import com.david.mydemo.ctl_storage.service.impl.StorageServiceImpl;
import com.david.mydemo.ctl_storage.util.LocalStorage;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@EnableConfigurationProperties(StorageProperties.class)
public class StorageAutoConfiguration {

    private final StorageProperties properties;

    public StorageAutoConfiguration(StorageProperties properties) {
        this.properties = properties;
    }

    @Bean
    public StorageServiceImpl storageService() {
        StorageServiceImpl storageService = new StorageServiceImpl();
        storageService.setLocalStorage(localStorage());
        return storageService;
    }

    @Bean
    public LocalStorage localStorage() {
        LocalStorage localStorage = new LocalStorage();
        StorageProperties.Local local = this.properties.getLocal();
        localStorage.setAddress(local.getAddress());
        localStorage.setStoragePath(local.getStoragePath());
        localStorage.setDownload(local.getDownload());
        return localStorage;
    }

}
